<%-- 
    Document   : fExposeNouveau
    Created on : 8 sept. 2012, 10:33:56
    Author     : david
--%>
<%@page import="java.util.Date"%>
<%@page import="fr.univ.colloque.data.Colloque"%>
<%@page import="fr.univ.colloque.data.Expose"%>
<%@page import="fr.univ.colloque.data.Personne"%>
<%@page import="fr.univ.colloque.data.Institution"%>
<%@page import="fr.univ.colloque.data.MotCle"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<script type="text/javascript">
<!--
var requete;

function valider() 
{
   var donnees = document.getElementById("email");
   var url = "ValiderEmail?v=" + escape(donnees.value);
   if (window.XMLHttpRequest) {
       requete = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
       requete = new ActiveXObject("Microsoft.XMLHTTP");
   }
   requete.open("GET", url, true);
   requete.onreadystatechange = majIHM;
   requete.send(null);
}

function majIHM() {
  var message = "";

  if (requete.readyState == 4) 
  {
    if (requete.status == 200) 
    {
      // exploitation des données de la réponse
      var messageTag = requete.responseXML.getElementsByTagName("message")[0];
      message = messageTag.childNodes[0].nodeValue;
      mdiv = document.getElementById("validationMessage");
      if (message == "invalide") 
      {
         mdiv.innerHTML = "<div class='error'>Email existe déjà</div>";
      }
    }
  }
}

//-->
</script>

<%--
1) Vérification de la présence d'un code erreur dans le cas d'un "retour"
après clique sur enregistré
2) Affichage du formulaire de saisie des données

--%>

<%

    String blockChamps = "";
    
    if ( session.getAttribute("user") != null )
        blockChamps = "disabled";

    List<String> lstMsgErreur = (ArrayList<String>) request.getAttribute("lstErr");

    if (lstMsgErreur != null)
    {
%>
<div class="error">
    <%
        for (int i = 0; i < lstMsgErreur.size(); i++)
        {
            out.println(lstMsgErreur.get(i));
            out.println("<br/>");
        }
    %>
    
</div>
<%
    }

    List<MotCle> lstMotCle;
    lstMotCle = (ArrayList<MotCle>) request.getAttribute("listeMotCle");

    Expose expose;
    expose = (Expose) request.getAttribute("expose");
    List<MotCle> lstMcExpo;
    MotCle mc1 = null;
    MotCle mc2 = null;
    MotCle mc3 = null;

    if (expose != null && expose.getLstMc() != null)
    {
        lstMcExpo = expose.getLstMc();
        if (lstMcExpo.size() >= 1)
        {
            mc1 = lstMcExpo.get(0);
        }

        if (lstMcExpo.size() >= 2)
        {
            mc2 = lstMcExpo.get(1);
        }

        if (lstMcExpo.size() >= 3)
        {
            mc3 = lstMcExpo.get(2);
        }
    }

%>

<div id="validationMessage"></div>

<form name="fSaisieExposePersonne" method="Post" action="./ProposeExpose">

    <p class="double">
        <label>Colloque:</label>
        <%
            Colloque colloque = (Colloque) session.getAttribute("Colloc");
            out.print(colloque.getTheme());
        %>
    </p>
    <fieldset>
        <legend>Personne</legend>
        <p class="double">
            <label for="nom">Nom :</label><input type="text" name="nom" id="nom" value="${expose.personne.nom}" <%= blockChamps %>>
        </p>
        <p class="double">
            <label for="prenom">Prénom : </label><input type="text" name="prenom" id="prenom" value="${expose.personne.prenom}" <%= blockChamps %>>
        </p>
        <p class="double">
            <label for="email">Email : </label><input type="text" name="email" id="email" value="${expose.personne.email}" <%= blockChamps %> onchange="valider()">
        </p>
        <p class="double">
            <label for="institution">Institution : </label>
            <select name="institution" size="1" <%= blockChamps %>>

                <option value="null">Selection...</option>
                <c:forEach items="${listeInstitution}" var="inst">
                    <c:if test="${expose.personne.institution.id == inst.id}">
                        <option value="${inst.id}" selected="true">${inst.libelle}</option>
                    </c:if>
                    <c:if test="${expose.personne.institution.id != inst.id}">
                        <option value="${inst.id}">${inst.libelle}</option>
                    </c:if>
                </c:forEach>        
            </select>
        </p>

        <p class="double">
            <label for="login">Login : </label><input type="text" name="login" id="login" value="${expose.personne.login}" <%= blockChamps %>>
        </p>
        <p class="double">
            <label for="motdepasse">Mot de passe : </label><input type="password" name="motdepasse" id="motdepasse" <%= blockChamps %>>
        </p>
    </fieldset>

    <fieldset>
        <legend>Exposé</legend>
        <p class="double">
            <label for="titre">Titre :</label><input type="text" name="titre" id="titre" value="${expose.libelle}">
        </p>
        <p class="double">
            <label for="resume">Résumé : </label><textarea id="resume" name="resume">${expose.resume}</textarea>
        </p>
        <p class="double">
            <label for="mc">Mot clé 1 : </label>
            <select name="mc1" size="1">
<% 
                for (int j = 0; j < lstMotCle.size(); j++)
                {
                    MotCle mc = lstMotCle.get(j);
                    if (mc1 != null && mc.getId() == mc1.getId())
                    {
%>
                        <option value="<%out.print(mc.getId());%>" selected="true"><%out.print(mc.getLibelle());%></option>
<%
                    }
                    else
                    {
%>
                        <option value="<%out.print(mc.getId());%>"><%out.print(mc.getLibelle());%></option>
<%
                    }
                }

%>
            </select>
        </p>
        <p class="double">
            <label for="mc">Mot clé 2 : </label>
            <select name="mc2" size="1">
<% 
                for (int j = 0; j < lstMotCle.size(); j++)
                {
                    MotCle mc = lstMotCle.get(j);
                    if (mc2 != null && mc.getId() == mc2.getId())
                    {
%>
                        <option value="<%out.print(mc.getId());%>" selected="true"><%out.print(mc.getLibelle());%></option>
<%
                    }
                    else
                    {
                    %>
                        <option value="<%out.print(mc.getId());%>"><%out.print(mc.getLibelle());%></option>
<%
                    }
                }

%>
            </select>

        </p>
        <p class="double">
            <label for="mc">Mot clé 3 : </label>
            <select name="mc3" size="1">
<% 
                for (int j = 0; j < lstMotCle.size(); j++)
                {
                    MotCle mc = lstMotCle.get(j);
                    if (mc3 != null && mc.getId() == mc3.getId())
                    {
%>
                        <option value="<%out.print(mc.getId());%>" selected="true"><%out.print(mc.getLibelle());%></option>
<%
                    }
                    else
                    {
%>
                        <option value="<%out.print(mc.getId());%>"><%out.print(mc.getLibelle());%></option>
<%
                    }
                }

%>
            </select>
        </p>
    </fieldset>

    <p class="simple">
        <input type="submit" value="Enregistrer"> <input type="button" value="Annuler" onClick="document.location.href='./AnnulerExpoNouveau'">
    </p>
</form>
